#include "../core/engine/interface.h"
#include "progressbar.h"

namespace sleek
{
    namespace gui
    {
        progressbar::progressbar(core::engine::interface *m) : frame(m)
        {
            min = 0;
            max = 100;
            per = lst = 0.f;
        }
        progressbar::~progressbar()
        {
        }
        void progressbar::setValue(core::s32 i)
        {
            lst = per;
            per = i/(max-min);
        }
        void progressbar::setMinValue(core::s32 i)
        {
            min = i;
        }
        void progressbar::setMaxValue(core::s32 i)
        {
            max = i;
        }
        void progressbar::setPercentage(core::f32 i)
        {
            per = i;
        }

        core::f32 progressbar::getPercentage()
        {
            return per;
        }
        core::s32 progressbar::getMinValue()
        {
            return min;
        }
        core::s32 progressbar::getMaxValue()
        {
            return max;
        }
        core::s32 progressbar:: getValue()
        {
            return (max-min)*per;
        }

        bool progressbar::manage(core::device::input *e)
        {
            bool CHovored = isHovored;
            if(frame::manage(e)) { return false; }
            if(e->type == core::device::EVENT_MOUSSE_MOVED) isHovored = box.intersect(e->mouse_pos);
            if(CHovored != isHovored)
            {
                e->gui.called = this;
                if(isHovored) { e->gui.code = gui::IET_PROGRESSBAR_HOVORED; return true; }
                else {  e->gui.code = gui::IET_PROGRESSBAR_FOCUSED; return true; }
            }
            if(per != lst)
            {
                e->gui.called = this;
                e->gui.code = gui::IET_PROGRESSBAR_UPDATED;
                return false;
            }
        }
        void progressbar::render()
        {
            if(!show) return;
            mom->getTheme()->drawProgressbar(this);
            renderChild();
        }
    }
}
